package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.UserInfoVo;
import com.tanhua.server.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessageController {

    @Autowired
    private MessageService messageService;

    /**
     * 聊天信息中，显示用户信息
     * @param huanxinId
     * @return
     */
    @GetMapping("/userinfo")
    public ResponseEntity getUserInfo(String huanxinId){
        UserInfoVo vo = messageService.findUserInfoByHuanxinId(huanxinId);
        return ResponseEntity.ok(vo);
    }

    /**
     * 添加联系人
     * @param paramMap
     * @return
     */
    @PostMapping("/contacts")
    public ResponseEntity addContacts(@RequestBody Map<String,Integer> paramMap){
        messageService.addContacts(paramMap);
        return ResponseEntity.ok(null);
    }

    /**
     * 联系人列表
     * @return
     */
    @GetMapping("/contacts")
    public ResponseEntity contactList(Long page, Long pagesize){
        PageResult pageResult = messageService.contactList(page,pagesize);
        return ResponseEntity.ok(pageResult);
    }
}
